﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SportsStore.Model;
using SportsStore.Repository.Initiaizers;

namespace SportsStore.Repository.Contexts
{
  public class SportsStoreDbContext : DbContext
  {
    public DbSet<Product> Products { get; set; }
    public DbSet<CartItem> CartItems { get; set; }
    public DbSet<Category> Categories { get; set; }

    public SportsStoreDbContext(string connectionString)
    : base(connectionString)
    {
    }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        //Default initialiser
        //Creates the database first time if it doesnt exist
        //Database.SetInitializer(new CreateDatabaseIfNotExists<SportsStoreDbContext>());
        
        //Recreates the database everytime the mode changes
        //Issus with this is that you loose data!!!!
        //Database.SetInitializer(new DropCreateDatabaseIfModelChanges<SportsStoreDbContext>());


        //Always recreates the database
        //Generally bad as loose data, no good for live at all!!!
        //Database.SetInitializer(new DropCreateDatabaseAlways<SportsStoreDbContext>());


        //Database.SetInitializer<SportsStoreDbContext>(null);
        Database.SetInitializer<SportsStoreDbContext>(new ProductTestInitializer());
        base.OnModelCreating(modelBuilder);
    }
  }
}
